import Http from '../../utils/Http';
const app = getApp();
const wxApi = require('../../utils/wxApi');
const constant = require("../../constant.js")

/**
 * 基础服务类
 */
export default class BaseService {

  constructor() {
    var that = this;
    wx.request({
      url: constant.api(false).url + '/tencent-auth',
      method: 'GET',
      header: {
        'content-type': 'application/json'
      },
      dataType: 'json',
      responseType: 'text',
      success: function (res) {
        if (res.data.data.tencetAuth.mock) {
          that.env = true
          //路径信息
          that.host = constant.api(that.env).url;


          //微信支付
          that.wxpay = wxApi.wxPay;

          //全局对象
          that.app = app;

          //网络请求
          that.get = Http.get.bind(Http);
          that.post = Http.post.bind(Http);
          that.patch = Http.patch.bind(Http);
          that.delete = Http.delete.bind(Http);
          that.put = Http.put.bind(Http);

        } else {
          that.env = true

          //路径信息
          that.host = constant.api(that.env).url;


          //微信支付
          that.wxpay = wxApi.wxPay;

          //全局对象
          that.app = app;

          //网络请求
          that.get = Http.get.bind(Http);
          that.post = Http.post.bind(Http);
          that.patch = Http.patch.bind(Http);
          that.delete = Http.delete.bind(Http);
          that.put = Http.put.bind(Http);
        }
      },
      fail: function () {
        that.env = false

        //路径信息
        that.host = constant.api(that.env).url;


        //微信支付
        that.wxpay = wxApi.wxPay;

        //全局对象
        that.app = app;

        //网络请求
        that.get = Http.get.bind(Http);
        that.post = Http.post.bind(Http);
        that.patch = Http.patch.bind(Http);
        that.delete = Http.delete.bind(Http);
        that.put = Http.put.bind(Http);
      }
    })
  }
}
